package com.bejoy.coolatin;

import com.tencent.tauth.Tencent;
import com.umeng.socialize.bean.RequestType;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.controller.UMServiceFactory;
import com.umeng.socialize.controller.UMSocialService;
import com.umeng.socialize.media.QQShareContent;
import com.umeng.socialize.media.QZoneShareContent;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.sso.QZoneSsoHandler;
import com.umeng.socialize.sso.UMSsoHandler;
import com.umeng.socialize.weixin.controller.UMWXHandler;
import com.umeng.socialize.weixin.media.CircleShareContent;
import com.umeng.socialize.weixin.media.WeiXinShareContent;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class UmengshareActivity extends Activity {
	private Button testbutton;
	UMSocialService mController;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_umengshare);
		testbutton = (Button) findViewById(R.id.testbutton);
		mController = UMServiceFactory.getUMSocialService("com.umeng.share");
		initialUM();

		testbutton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				mController.openShare(UmengshareActivity.this, false);
			}
		});
	}

	@SuppressWarnings("deprecation")
	private void initialUM() {
		// "wx2a22edf1be46e21b"
		UMWXHandler wxHandler = new UMWXHandler(UmengshareActivity.this,
				"wx3ea06023685210bd");
		wxHandler.addToSocialSDK();
		WeiXinShareContent WeixinShareContent1 = new WeiXinShareContent();
		WeixinShareContent1.setTitle("木头人2");
		WeixinShareContent1.setTargetUrl("http://www.baidu.com");
		// 设置分享文字内容
		WeixinShareContent1.setShareContent("234木头人........");
		// 设置分享图片
		WeixinShareContent1.setShareImage(new UMImage(UmengshareActivity.this,
				"http://www.cn-csec.com/templates/default/images/at5.jpg"));
		mController.setShareMedia(WeixinShareContent1);
		// 朋友圈
		UMWXHandler wxCircleHandler = new UMWXHandler(UmengshareActivity.this,
				"wx3ea06023685210bd");
		wxCircleHandler.setToCircle(true);
		wxCircleHandler.addToSocialSDK();
		CircleShareContent CircleShareContent1 = new CircleShareContent();  
		CircleShareContent1.setTitle("木头人");  
		CircleShareContent1.setTargetUrl("http://www.baidu.com");  
		  
		CircleShareContent1.setShareImage(new UMImage(UmengshareActivity.this,  
		        "http://www.cn-csec.com/templates/default/images/at5.jpg"));  
		CircleShareContent1.setShareContent("123木头人........");  
		mController.setShareMedia(CircleShareContent1);  
		mController.getConfig().removePlatform(SHARE_MEDIA.RENREN,  
		        SHARE_MEDIA.DOUBAN);  
		// 腾讯微博
		com.umeng.socialize.sso.TencentWBSsoHandler tencentWBSsoHandler = new com.umeng.socialize.sso.TencentWBSsoHandler();
		tencentWBSsoHandler.addToSocialSDK();
		com.umeng.socialize.media.TencentWbShareContent tencentWbShareContent = new com.umeng.socialize.media.TencentWbShareContent();
		mController.setShareMedia(tencentWbShareContent);
		mController.getConfig().setSsoHandler(tencentWBSsoHandler);
		// QQ空间
		QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(this,
				"100424468", "c7394704798a158208a74ab60104f0ba");
		qZoneSsoHandler.addToSocialSDK();
		// qZoneSsoHandler.setTargetUrl(SHARETargetUrl);
		QZoneShareContent qZoneShareContent = new QZoneShareContent();
		// qZoneShareContent.setTitle(SHARETitle);
		// qZoneShareContent.setShareContent(SHAREText);
		// qZoneShareContent.setTargetUrl(SHARETargetUrl);
		// if (umImage != null) {
		// qZoneShareContent.setShareImage(umImage);
		// }
		mController.setShareMedia(qZoneShareContent);
		mController.getConfig().setSsoHandler(qZoneSsoHandler);
		com.umeng.socialize.sso.UMQQSsoHandler qqSsoHandler = new com.umeng.socialize.sso.UMQQSsoHandler(
				this, "101101365", "402cc0b0fe7bf6d33c27ba40d31ff537");
		qqSsoHandler.addToSocialSDK();
		// qqSsoHandler.setTargetUrl(SHARETargetUrl);
		QQShareContent qqShareContent = new QQShareContent();
		qqShareContent.setShareContent("123");
		qqShareContent.setTitle("啦啦啦");
		qqShareContent.setTargetUrl("http://www.baidu.com");
		mController.setShareMedia(qqShareContent);
		mController.getConfig().setSsoHandler(qqSsoHandler);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		/** 使用SSO授权必须添加如下代码 */
		UMSsoHandler ssoHandler = mController.getConfig().getSsoHandler(
				requestCode);
		if (ssoHandler != null) {
			ssoHandler.authorizeCallBack(requestCode, resultCode, data);
		}
	}
}
